/**
* Copyright (C) 2016, GIAYBAC
*
* Released under the MIT license
*/
package com.vegetable.modules.entity.bank.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

@Slf4j
@Data
public class AliPayTran implements Serializable {
	private static final long serialVersionUID = 1L;

	@Excel(name ="交易时间", fixedIndex = 0, format = "yyyy-MM-dd HH:mm:ss")
	private Date tradingTime;

	@Excel(name ="交易分类", fixedIndex = 1)
	private String tradingCategory;

	@Excel(name ="交易对方", fixedIndex = 2)
	private String counterparty;

	@Excel(name ="对方账号", fixedIndex = 3)
	private String counterpartyAccount;

	@Excel(name ="商品说明", fixedIndex = 4)
	private String tradingDescription;

	@Excel(name ="收/支", fixedIndex = 5)
	private String tradingType;

	@Excel(name ="金额", fixedIndex = 6)
	private String tradingAmountStr;

	@ApiModelProperty(name ="金额(元)")
	private BigDecimal tradingAmount;

	@Excel(name ="收/付款方式", fixedIndex = 7)
	private String payType;

	@Excel(name ="交易状态", fixedIndex = 8)
	private String payStatus;

	@Excel(name ="交易订单号", fixedIndex = 9)
	private String tradingNo;

	@Excel(name ="商家订单号", fixedIndex = 10)
	private String orderNo;

	@Excel(name ="备注", fixedIndex = 11)
	private String remark;

	public String convertTradingType(){
		String result = "";
		switch (tradingType){
			case "收入":
				result = "INCOME";
				break;
			case "支出":
				result = "EXPENSE";
				break;
			default:
				result = "OTHER";
				break;
		}
		return result;
	}

	public String getOrderNo(){
		if(StringUtils.isNotEmpty(orderNo)){
			return orderNo.replace("\t", "");
		}else{
			log.info("{}的商户单号是空的", tradingDescription);
			return "";
		}
	}

	public BigDecimal getTradingAmount() {
		if (tradingAmountStr == null) return null;
		// 清理货币符号和千位分隔符（保留小数点和负号）
		String cleanValue = tradingAmountStr
				.replaceAll("[^\\d.-]", "")  // 移除非数字、非小数点、非负号
				.replaceAll("(?<=\\d)-(?=\\d)", ""); // 移除数字间的短横（如千位分隔符）

		// 处理空字符串
		if (cleanValue.isEmpty()) return null;
		return new BigDecimal(cleanValue);
	}
	
}
